package edu.kit.ksri.db.mturk.standaloneutils;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.amazonaws.mturk.service.axis.RequesterService;
import com.amazonaws.mturk.util.PropertiesClientConfig;

import edu.kit.ksri.db.mturk.connectionhandlers.HITManager;
import edu.kit.ksri.db.mturk.var.StaticInformation;

/**
 * Copyright (c) 2010-2011 Karlsruhe Institute of Technology (KIT), Germany
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
 * --------------------------------------------------------------------------
 * 
 * Software: CSP/WMV tool for dynamic quality management of microtasks
 * http://www.ksri.kit.edu/Upload/Users/PeopleClouds/HCOMP2011_An_extendable_toolkit_for_managing_quality_of_human-based_eServices.pdf
 * 
 * Organization: Karlsruhe Institute of Technology (KIT), Germany
 * http://www.kit.edu
 * 
 * Project: PeopleClouds project of the Karlsruhe Service Research Institute(KSRI)
 * http://www.ksri.kit.edu/Default.aspx?PageId=818
 * 
 * Contributing authors: David Bermbach, Sandra Rath, Pascal Wichmann, Robert Kern
 * 
 * ---------------------------------------------------------------------------
 * 
 * Purpose: This class registers a new HITType on MTurk. The results are needed for the
 * properties file in the method createHITs in class {@link HITManager}.
 * Parameters can be defined below.
 */
public class HITTypeCreator {

	public static void main(String[] args) throws Exception {
		PropertyConfigurator.configure("log4j.properties");
		basiclog.info("Creating requestor service object...");
		RequesterService rs = new RequesterService(new PropertiesClientConfig(
				StaticInformation.mturkFile));
		basiclog.info("Trying to create hit type with specified parameters");
		
		//Register the HIT type
		String hittypeid = rs.registerHITType(StaticInformation.scenario.getHitAutoApprovalDelayInSeconds(),
				StaticInformation.scenario.getHitAssignmentDurationInSeconds(), StaticInformation.scenario.getHitReward(), StaticInformation.scenario.getHitTitle(), StaticInformation.scenario.getHitKeywords(),
				StaticInformation.scenario.getHitDescription(), StaticInformation.scenario.getHitQualRequirements());
		basiclog.info("Successfully created HIT Type."
				+ " The Hit Type id is (without quotation marks) \""
				+ hittypeid + "\".");

	}

	private static Logger basiclog = Logger.getLogger("basic."
			+ HITTypeCreator.class);
}
